#管理员工接口案例

# import requests
# from api.ihrmEmpManageApi import EmpManageApi
# from common.assertTools import common_assret
#
#
# class TestAddEmp(object):
#
#      def test01_add_success(self):
#          emp = EmpManageApi()
#
#          resp = requests.post(url="http://ihrm2-test.itheima.net/api/sys/login",
#                               json={"mobile": "13800000002", "password": "123456"})
#          print("登录成功", resp.json())
#          token = resp.json().get("data")
#          req_header = {"Content-Type": "application/json", "Authorization": token}
#          # 添加员工
#          req_body = {"username": "张三疯007", "mobile": "18923432344", "workNumber": "9527"}
#          resp = emp.add_emp(req_header, req_body)
#          print("添加成功:", resp.json())
#
#          common_assret(resp, 200,True,10000,"操作成功")
#      def test02_mobile_none(self): #手机号空
#          emp = EmpManageApi()
#
#          resp = requests.post(url="http://ihrm2-test.itheima.net/api/sys/login",
#                               json={"mobile": "13800000002", "password": "123456"})
#          print("登录成功", resp.json())
#          token = resp.json().get("data")
#          req_header = {"Content-Type": "application/json", "Authorization": token}
#          # 添加员工
#          req_body = {"username": "张三疯007", "mobile": None, "workNumber": "9527"}
#          resp = emp.add_emp(req_header, req_body)
#          print("添加成功:", resp.json())
#
#          common_assret(resp, 200, False, 20002, "新增员工失败")
#      def test03_no_params(self):#无参
#          emp = EmpManageApi()
#
#          resp = requests.post(url="http://ihrm2-test.itheima.net/api/sys/login",
#                               json={"mobile": "13800000002", "password": "123456"})
#          print("登录成功", resp.json())
#          token = resp.json().get("data")
#          req_header = {"Content-Type": "application/json", "Authorization": token}
#          # 添加员工
#          req_body =None
#          resp = emp.add_emp(req_header, req_body)
#          print("添加成功:", resp.json())
#
#          common_assret(resp, 200, False, 99999, "抱歉，系统繁忙，请稍后重试")
import requests
from api.ihrmEmpManageApi import EmpManageApi
from common.DBT框架 import DBTools
from common.assertTools import common_assret
from config import TEL


class TestAddEmp(object):
    def setup_class(self):
        self.emp = EmpManageApi()

        resp = requests.post(url="http://ihrm2-test.itheima.net/api/sys/login",
                             json={"mobile": "13800000002", "password": "123456"})
        print("登录成功", resp.json())
        token = resp.json().get("data")
        self.req_header = {"Content-Type": "application/json", "Authorization": token}
    def setup(self):
        DBTools.db_iud(f"delete from bs_user where mobile ='{TEL}'")   #开始删除一次不重复
    def teardown(self):
        DBTools.db_iud(f"delete from bs_user where mobile ='{TEL}'") #测试后删除一次不保留

    def test01_add_success(self):

         # 添加员工
         req_body = {"username": "张三疯007", "mobile": TEL, "workNumber": "9527"}
         resp =self.emp.add_emp(self.req_header, req_body)
         print("添加成功:", resp.json())

         common_assret(resp, 200,True,10000,"操作成功")
    def test02_mobile_none(self): #手机号空

         # 添加员工
         req_body = {"username": "张三疯007", "mobile": None, "workNumber": "9527"}
         resp = self.emp.add_emp(self.req_header, req_body)
         print("添加成功:", resp.json())

         common_assret(resp, 200, False, 20002, "新增员工失败")
    def test03_no_params(self):#无参

         # 添加员工
         req_body =None
         resp =self. emp.add_emp(self.req_header, req_body)
         print("添加成功:", resp.json())

         common_assret(resp, 200, False, 99999, "抱歉，系统繁忙，请稍后重试")